package com.study.webapp.springThink.beandefinition;

import com.study.webapp.springThink.domain.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;

import static org.springframework.beans.factory.support.BeanDefinitionBuilder.genericBeanDefinition;

/**
 * @program: study
 *
 * @description:
 *
 * @author: heqiang
 *
 * @create: 2020-06-21 20:53
 **/
public class AnnotationDependencyInjectionResolutionDemo {

    //DependencyDescriptor ->
    //必须(requried=true)
    //实时注入(eager = true)
    //通过类型(User.class)
    //字段名称("user")
    @Autowired
    private User user;

    public static void main(String[] args) {
        //创建beanFactory工厂
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        //注册configuration配置类
        applicationContext.register(AnnotationDependencyInjectionResolutionDemo.class);

        XmlBeanDefinitionReader reader = new XmlBeanDefinitionReader(applicationContext);
        String xmlReader = "";
        reader.loadBeanDefinitions(xmlReader);

        //启动应用上下文
        applicationContext.refresh();
        //关闭上下文
        applicationContext.close();
    }





    /**
     * 1,@Bean方式定义
     */
    @Component
    public static class Config {

        @Bean
        public User user() {
            User user = new User();
            user.setId(1L);
            user.setName("heqiang");
            return user;
        }
    }
}
